<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>组织架构 - 部门管理</title>


<link
	href='http://fonts.useso.com/css?family=Open+Sans:400,300,400italic,700'
	rel='stylesheet' type='text/css'>
<link href="./css/font-awesome.min.css" rel="stylesheet">
<link href="./css/bootstrap.min.css" rel="stylesheet">
<link href="./css/jquery-confirm.css" rel="stylesheet">
<link href="./css/templatemo-style.css" rel="stylesheet">
<link rel="stylesheet" href="./css/zTreeStyle/zTreeStyle.css"
	type="text/css">
<script src="./js/jquery-1.11.2.min.js"></script>
<script src="./js/bootstrap.js"></script>
<script type="text/javascript" src="./js/jquery-confirm.js"></script>
<script type="text/javascript" src="./js/jquery.page.js"></script>
<!-- jQuery -->
<script type="text/javascript" src="./js/jquery.ztree.core-3.5.js"></script>
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
      <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
      <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->


<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
      <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
      <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->

</head>
<body>
	<!-- Left column -->
	<div class="templatemo-flex-row">
		<div class="templatemo-sidebar">
			<header class="templatemo-site-header">
				<div class="square"></div>
				<h1>组织架构</h1>
			</header>

			<!-- Search box -->
			<form class="templatemo-search-form" role="search">
				<div class="input-group">
					<button type="submit" class="fa fa-search"></button>
					<input type="text" class="form-control" placeholder="Search"
						name="srch-term" id="srch-term">
				</div>
			</form>
			<div class="templatemo-content">
				<ul id="treeDemo" class="ztree"></ul>
			</div>
		</div>
		<!-- Main content -->
		<div class="templatemo-content col-1 light-gray-bg">
			<div class="templatemo-top-nav-container">
				<div class="row">
					<nav class="templatemo-top-nav col-lg-12 col-md-12">
						<ul class="text-uppercase">
							<li><a href="home">主页</a></li>
							<li><a id="dep" href="#" class="active">部门管理</a></li>
							<li><a id="person" href="#">人员管理</a></li>
							<li><a href="logout">退出</a></li>
						</ul>
					</nav>
				</div>
			</div>
			<div class="templatemo-content-container">
				<div>
					<a id="tabel" href="#" class="templatemo-edit-btn"><span><img
							src="./images/t01.png" /></span>添加部门</a>
				</div>
				<!-- Modal -->

				<div class="templatemo-content-widget no-padding">
					<div class="panel panel-default table-responsive">

						<table 
							class="table table-striped table-bordered templatemo-user-table">
							<thead>
								<tr>
									<td><a href="#" class="white-text templatemo-sort-by">编号
											<span class="caret"></span>
									</a></td>
									<td><a  href="#" class="white-text templatemo-sort-by">名称<span
											class="caret"></span></a></td>
									<td><a href="#" class="white-text templatemo-sort-by">地址
											<span class="caret"></span>
									</a></td>
									<td><a href="#" class="white-text templatemo-sort-by">联系方式
											<span class="caret"></span>
									</a></td>
									<td><a href="#" class="white-text templatemo-sort-by">行政级别
											<span class="caret"></span>
									</a></td>
									<td><a href="#" class="white-text templatemo-sort-by">行政编码
											<span class="caret"></span>
									</a></td>
									<td><a href="#" class="white-text templatemo-sort-by">上级主管部门
											<span class="caret"></span>
									</a></td>
									<td align="center">编辑</td>
									<td align="center">删除</td>
								</tr>
							</thead>
							<tbody id="orgTb">

							</tbody>
						</table>
					</div>
					<div class="tcdPageCode"></div>
				</div>
				<footer class="text-center">
					<p>Copyright &copy; 2015 宁波市政务云计算中心</p>
				</footer>
			</div>
		</div>
	</div>

	
	<!-- Templatemo Script -->
	<script type="text/javascript">
	
	
     var setting = {
      data: {
        simpleData: {
          enable: true
        }
      }
    }; 

    /* var zNodes =[
      { id:1, pId:0, name:"公安局", url:"orglist",target:"_self",open:true, iconOpen:"./css/zTreeStyle/img/diy/1_open.png", iconClose:"./css/zTreeStyle/img/diy/1_close.png"},
      { id:11, pId:1, name:"交管局",  url:"orglist",target:"_self",open:true,icon:"./css/zTreeStyle/img/diy/1_open.png", iconClose:"./css/zTreeStyle/img/diy/1_close.png"},
      { id:12, pId:1, name:"交警局",  url:"orglist",target:"_self",open:true,icon:"./css/zTreeStyle/img/diy/1_open.png", iconClose:"./css/zTreeStyle/img/diy/1_close.png"},
      { id:121, pId:12, name:"支队1",  url:"personlist",target:"_self",open:false,icon:"./css/zTreeStyle/img/diy/1_open.png", iconClose:"./css/zTreeStyle/img/diy/1_close.png"},
      { id:122, pId:12, name:"支队2",  url:"personlist",target:"_self",open:false,icon:"./css/zTreeStyle/img/diy/1_open.png", iconClose:"./css/zTreeStyle/img/diy/1_close.png"},
      { id:1211, pId:121, name:"人员1", icon:"./css/zTreeStyle/img/diy/user.png"},
      { id:1212, pId:121, name:"人员2", icon:"./css/zTreeStyle/img/diy/user.png"},
      { id:1221, pId:122, name:"人员1", icon:"./css/zTreeStyle/img/diy/user.png"},
      { id:1222, pId:122, name:"人员2", icon:"./css/zTreeStyle/img/diy/user.png"},
      { id:2, pId:0, name:"工商局",  url:"orglist",target:"_self",open:true, iconOpen:"./css/zTreeStyle/img/diy/1_open.png", iconClose:"./css/zTreeStyle/img/diy/1_close.png"},
      { id:21, pId:2, name:"科室1",  url:"personlist",target:"_self",open:false,icon:"./css/zTreeStyle/img/diy/1_open.png", iconClose:"./css/zTreeStyle/img/diy/1_close.png"},
      { id:22, pId:2, name:"科室2", url:"personlist",target:"_self",open:false,icon:"./css/zTreeStyle/img/diy/1_open.png", iconClose:"./css/zTreeStyle/img/diy/1_close.png"},
      { id:211, pId:21, name:"人员1", icon:"./css/zTreeStyle/img/diy/user.png"},
      { id:212, pId:21, name:"人员2", icon:"./css/zTreeStyle/img/diy/user.png"},
      { id:221, pId:22, name:"人员1", icon:"./css/zTreeStyle/img/diy/user.png"},
      { id:222, pId:22, name:"人员2", icon:"./css/zTreeStyle/img/diy/user.png"},
      { id:3, pId:0, name:"司法局",  url:"orglist",target:"_self",open:true, iconOpen:"./css/zTreeStyle/img/diy/1_open.png", iconClose:"./css/zTreeStyle/img/diy/1_close.png"},
      { id:31, pId:3, name:"科室1", url:"personlist",target:"_self",open:false,icon:"./css/zTreeStyle/img/diy/1_open.png", iconClose:"./css/zTreeStyle/img/diy/1_close.png"},
      { id:32, pId:3, name:"科室2",url:"personlist",target:"_self",open:false, icon:"./css/zTreeStyle/img/diy/1_open.png", iconClose:"./css/zTreeStyle/img/diy/1_close.png"},
      { id:311, pId:31, name:"人员1", icon:"./css/zTreeStyle/img/diy/user.png"},
      { id:312, pId:31, name:"人员2", icon:"./css/zTreeStyle/img/diy/user.png"},
      { id:321, pId:32, name:"人员1", icon:"./css/zTreeStyle/img/diy/user.png"},
      { id:322, pId:32, name:"人员2", icon:"./css/zTreeStyle/img/diy/user.png"},
    ]; */

    $(document).ready(function(){
       // alert("1");
    	  $.ajax(
 	    	    {url:"listorgtree", 
 	        	 dataType:"json",
 	        	 contentType: "application/x-www-form-urlencoded; charset=utf-8", 
 	        	 type:"POST",
 				success:function (data) {
 					$.fn.zTree.init($("#treeDemo"), setting, data);
 	        		   
 	    },
 	    error:function(){alert("出错啦！");}});

    
     $.ajax(
	    	    {url:"listorg", 
	        	 dataType:"json",
	        	 contentType: "application/x-www-form-urlencoded; charset=utf-8", 
	        	 type:"POST",
				success:function (data) {
		        	  // alert(data.length);
		        	   $.each(data, function(index, item) {
	   		        		  // alert(item["id"]);
	   		        		  // alert(index);
	   		        		  if(index<8){
	   		        		  var level="一级行政机构";
	   		        		  if(item["level"]==1) level="一级行政机构";
	   		        		  else if(item["level"]==2) level="二级行政机构";
	   		        		  else if(item["level"]==3) level="三级行政机构";
	   		        		  else if(item["level"]==4) level="四级行政机构";
	   		        		  else level="特殊行政机构";
	   		        		 var orgTb=document.getElementById("orgTb");
	   	 	        			var row=orgTb.insertRow(index);
	   	 	        			row.insertCell(0).innerHTML=item["id"];
	   	 	        			row.insertCell(1).innerHTML=item["name"];
	   	 	        			row.insertCell(2).innerHTML=item["address"];
	   	 	        			row.insertCell(3).innerHTML=item["phone"];
	   	 	        			row.insertCell(4).innerHTML=level;
	   	 	        			row.insertCell(5).innerHTML=item["sn"];
	   	 	        			row.insertCell(6).innerHTML=item["porg"];
	   	 	        			row.insertCell(7).innerHTML="<a  onclick=\"edit("+item["id"]+")\" class=\"templatemo-edit-btn\">编辑</a>";
	   	 	        			row.insertCell(8).innerHTML="<a  onclick=\"del("+item["id"]+")\" class=\"templatemo-link\">删除</a>";  
	   		        		  }});  
		        		  if(data!=null&& data!=undefined && data!=""){	       
		        	$(".tcdPageCode").createPage({
        			pageCount:Math.ceil(data.length/8.0),
       				current:1,
        			backFn:function(p){
        				var tb=document.getElementById("orgTb");
        				var t=data.length-(Math.ceil(data.length/8.0)-1)*8;
							for(var i=7;i>=t;i--){
								for(var j=0;j<9;j++)
								tb.rows[i].cells[j].style.display="";
								}
        				 $.each(data, function(index, item) {
   		        		  // alert(item["id"]);
   		        		  if(index>=8*(p-1)&&index<8*p){
   		        			// alert(index);
   		        		  var level="一级行政机构";
   		        		  if(item["level"]==1) level="一级行政机构";
   		        		  else if(item["level"]==2) level="二级行政机构";
   		        		  else if(item["level"]==3) level="三级行政机构";
   		        		  else if(item["level"]==4) level="四级行政机构";
   		        		  else level="特殊行政机构";
   		        		  var row=index%8;
   		        		//  alert(row);
   		        		
   	 	        			//var row=orgTb.insertRow(index);
   	 	        		tb.rows[row].cells[0].innerHTML=item["id"];
   	 	        		tb.rows[row].cells[1].innerHTML=item["name"];
   	 	        		tb.rows[row].cells[2].innerHTML=item["address"];
   	 	        		tb.rows[row].cells[3].innerHTML=item["phone"];
   	 	    			tb.rows[row].cells[4].innerHTML=level;
   	 					tb.rows[row].cells[5].innerHTML=item["sn"];
   						tb.rows[row].cells[6].innerHTML=item["porg"];
   						tb.rows[row].cells[7].innerHTML="<a  onclick=\"edit("+item["id"]+")\" class=\"templatemo-edit-btn\">编辑</a>";
   						tb.rows[row].cells[8].innerHTML="<a  onclick=\"del("+item["id"]+")\" class=\"templatemo-link\">删除</a>";  
   		        		  }
   		        		  }); 
        				 if(p==Math.ceil(data.length/8.0)){
 							var t=data.length-(p-1)*8;
 							for(var i=7;i>=t;i--){
 								for(var j=0;j<9;j++)
 								tb.rows[i].cells[j].style.display="none";
 								}
 							} 	       
        			}
   					 });
		        		  } else {
		        			  $.confirm({
		        				   keyboardEnabled: true,
		    	             	    //title: false, // hides the title.
		    	             	    content: '该部门下没有子部门，请添加！',
		    	             	    cancelButton: false, // hides the cancel button.
		    	             	    confirmButtonClass: 'btn-info',
		    	             	   autoClose: 'confirm|3000'
		    	             	});
			        		  }
	        		  
	    },
	    error:function(){alert("出错啦！");}});
    }); 
    $("#dep").click(function(){  
    	location.href = "orglist?"+Math.random();
     });
    $("#person").click(function(){  
    	location.href = "personlist?"+Math.random();
     });
    $("#tabel").click(function(){
       
    	
    	$.confirm({
    		keyboardEnabled: true,
    	    title: '添加部门',
    	    content: function($obj){
    	    	return $.ajax({
    	             url:"getparentorg",
    	             dataType:"json",
    	             type:"POST",
    	             success:function (data) {
    	            	 var parentorg="";
    	             	 $.each(data, function(index, item) {
    	             		parentorg=parentorg+"'<option value=\""+item["id"]+"\">"+item["name"]+"</option>'"
    	             		// alert(parentorg);
    	             	 });
    	             	 $obj.setContent('  <form id ="orgadd"  class="templatemo-login-form" method="post" >'+
    	                 	    '<div class="row form-group">'+
    	                        '<div class="col-lg-6 col-md-6 form-group">'+                  
    	                   ' <label for="inputFirstName">名称</label>'+
    	                    '<input type="text" class="form-control" name="name" placeholder="XX局"> '+                 
    	                '</div>'+
    	                '<div class="col-lg-6 col-md-6 form-group"> '+                 
    	                   ' <label for="inputLastName">地址</label>'+
    	                   ' <input type="text" class="form-control" name="address" placeholder="宁波市XX路XX号"> '+                 
    	                '</div>'+ 
    	              '</div>'+
    	              '<div class="row form-group">'+
    	              '<div class="col-lg-6 col-md-6 form-group">'+                  
    	         		' <label for="inputFirstName">联系方式</label>'+
    	          		'<input type="text" class="form-control" name="phone" placeholder="123456"> '+                 
    	        		'</div>'+
    	        		'<div class="col-lg-6 col-md-6 form-group"> '+                 
    	         		'<label class="control-label templatemo-block">行政级别</label>'+
    	         		'   <select name="level" class="form-control">'+
    	                           '<option value="1">一级行政机构</option>'+
    	                            '<option value="2">二级行政机构</option>'+  
    	                            '<option value="3">三级行政机构</option>'+  
    	                            '<option value="4">四级行政机构</option>'+  
    	                            '<option value="5">特殊级行政机构</option>'+                     
    	                          '</select>'+                 
    	        		'</div>'+ 
    	        		'</div>'+
    	        		'<div class="row form-group">'+
    	        		'<div class="col-lg-6 col-md-6 form-group">'+                  
    	        		' <label for="inputFirstName">行政编码</label>'+
    	        		'<input type="text" class="form-control" name="sn" placeholder="SD001"> '+                 
    	        		'</div>'+
    	        		'<div class="col-lg-6 col-md-6 form-group"> '+                 
    	        		'<label class="control-label templatemo-block">上级主管部门</label>'+
    	         		'   <select name="pid" class="form-control">'+
    	         		parentorg +                     
    	                          '</select>'+                 
    	        		'</div>'+ 
    	        		'</div>'+
    	        		'</form>');
    	             },
    	             error:function () {
    	             	$.confirm({
    	             		keyboardEnabled: true,
    	             	    title: false, // hides the title.
    	             	    content: '获取主管部门失败，请重新获取！',
    	             	    cancelButton: false, // hides the cancel button.
    	             	    closeIcon: false // hides the close icon.
    	             	});
    	             }
    	         });   
    	         },
    	    confirmButtonClass: 'btn-info',
    	    cancelButtonClass: 'btn-danger',
    	    confirm: function(){ 
        	    $.ajax({
                url:"addorg",
                dataType:"json",
                type:"POST",
                data:$("#orgadd").serializeArray(),
                success:function (data) {
                	$.confirm({
                		keyboardEnabled: true,
                	    title: '添加成功',
                	    content: '添加部门成功！',
                	    autoClose: 'confirm|3000'
                	});
                },
                error:function () {
                	$.confirm({
                		keyboardEnabled: true,
                	    title: false, // hides the title.
                	    content: '添加部门失败，请重新添加！',
                	    cancelButton: false, // hides the cancel button.
                	    closeIcon: false // hides the close icon.
                	});
                }
            }); 
    	    	
    	    }
    	});
     });
   function edit(oid){
    	$.confirm({
    		keyboardEnabled: true,
    	    title: '编辑部门',
    	    content: function($obj){
    	    	return $.ajax({
    	             url:"editorg",
    	             data:{"oid":oid},
    	             dataType:"json",
    	             type:"POST",
    	             success:function (data) {
        	             var orglevel="";
        	             var levellist=new Array("","一级行政组织","二级行政组织","三级行政组织","四级行政组织","特殊行政组织");
        	             for(var i=1;i<6;i++){
            	             if(data["level"]==i) {orglevel=orglevel+"'<option selected=\"selected\" value=\""+i+"\" >"+levellist[i]+"</option>'";}
            	             else orglevel=orglevel+"'<option value=\""+i+"\" >"+levellist[i]+"</option>'";
            	             }
        	           //  alert(data);
    	             	 $obj.setContent('  <form id ="orgedit"  class="templatemo-login-form" method="post" >'+
    	                 	    '<div class="row form-group">'+
    	                        '<div class="col-lg-6 col-md-6 form-group">'+                  
    	                   ' <label for="inputFirstName">名称</label>'+
    	                    '<input type="text" class="form-control" name="name"  value="'+data["name"]+'"> '+                 
    	                '</div>'+
    	                '<div class="col-lg-6 col-md-6 form-group"> '+                 
    	                   ' <label for="inputLastName">地址</label>'+
    	                   ' <input type="text" class="form-control" name="address"  value="'+data["address"]+'"> '+              
    	                '</div>'+ 
    	              '</div>'+
    	              '<div class="row form-group">'+
    	              '<div class="col-lg-6 col-md-6 form-group">'+                  
    	         		' <label for="inputFirstName">联系方式</label>'+
    	          		'<input type="text" class="form-control" name="phone"  value="'+data["phone"]+'"> '+                
    	        		'</div>'+
    	        		'<div class="col-lg-6 col-md-6 form-group">'+                  
    	        		' <label for="inputFirstName">行政编码</label>'+
    	        		'<input type="text" class="form-control" name="sn"  value="'+data["sn"]+'"> '+                 
    	        		'</div>'+
    	        		'</div>'+
    	        		'<div class="row form-group">'+
      	              '<div class="col-lg-6 col-md-6 form-group">'+                  
      	         		' <label for="inputFirstName">行政级别</label>'+
      	         		'   <select name="level" class="form-control">'+
      	         		orglevel+                   
                       '</select>'+                 
      	        		'</div>'+
      	        		'<div class="col-lg-6 col-md-6 form-group">'+                  
      	        		' <label for="inputFirstName">上级主管部门</label>'+
      	        		'<input type="text" class="form-control" name="porg"  value="'+data["porg"]+'"> '+ 
      	        		'<input type="hidden"  name="pid"  value="'+data["pid"]+'"> '+   
      	        		'<input type="hidden"  name="id"  value="'+data["id"]+'"> '+                 
      	        		'</div>'+
      	        		'</div>'+
    	        		'</form>');
    	             },
    	             error:function () {
    	             	$.confirm({
    	             		keyboardEnabled: true,
    	             	    title: false, // hides the title.
    	             	    content: '获取信息失败，请重新获取！',
    	             	    cancelButton: false, // hides the cancel button.
    	             	    closeIcon: false // hides the close icon.
    	             	});
    	             }
    	         });   
    	         },
    	    confirmButtonClass: 'btn-info',
    	    cancelButtonClass: 'btn-danger',
    	    confirm: function(){ 
        	    $.ajax({
                url:"confirmeditorg",
                dataType:"json",
                type:"POST",
                data:$("#orgedit").serializeArray(),
                success:function (data) {
                	$.confirm({
                		keyboardEnabled: true,
                	    title: '修改成功',
                	    content: '修改部门信息成功！',
                	    autoClose: 'confirm|3000'
                	});
                },
                error:function () {
                	$.confirm({
                		keyboardEnabled: true,
                	    title: false, // hides the title.
                	    content: '修改部门信息失败，请重新修改！',
                	    cancelButton: false, // hides the cancel button.
                	    closeIcon: false // hides the close icon.
                	});
                }
            }); 
    	    	
    	    }
    	});
     }
   function del(oid){
   	$.confirm({
   		keyboardEnabled: true,
   	    title: '删除部门',
   	    content: '此操作不可撤销，确定删除该部门？',
   	    confirmButtonClass: 'btn-info',
   	    cancelButtonClass: 'btn-danger',
   	    confirm: function(){ 
       	    $.ajax({
               url:"delorg",
               dataType:"json",
               type:"POST",
               data:{"oid":oid},
               success:function (data) {
               	$.confirm({
               		keyboardEnabled: true,
               	    title: '删除成功',
               	    content: '删除部门成功！',
               	    autoClose: 'confirm|3000'
               	});
               },
               error:function () {
               	$.confirm({
               		keyboardEnabled: true,
               	    title: false, // hides the title.
               	    content: '删除部门失败，请重新操作！',
               	    cancelButton: false, // hides the cancel button.
               	    closeIcon: false // hides the close icon.
               	});
               }
           }); 
   	    	
   	    }
   	});
    }
   </script>
</body>
</html>
